import {createRouter,createWebHistory} from 'vue-router'
import Home from '../components/Home.vue'
import Login from '../components/Login.vue'
let router=createRouter({
    history: createWebHistory(),
    routes:[
        {
            path: '/home',
            component: Home
        },
        {
            path: '/login',
            component: Login
        }
    
    ]
});
import { useRouter } from 'vue-router'
let router1=useRouter();
router.beforeEach((to, from, next) => {
    const username = window.sessionStorage.getItem('username');
    if (to.path === '/login') {
        next();
    }else{
        if (username) {
            next();
        } else {
            next('/login');
        }
    }
});
export default router;